Ext.define('AM.controller.management.TitleToolbar', {

	extend : 'Ext.app.Controller',
	stores : ['bazadedate.Articole', 'management.Investitii'],
	views : ['toolbars.TitleToolbar', 'grids.management.Investitii', 'windows.CreazaInvestitie',
			'windows.DeschideInvestitia'],

	init : function() {
		console.log('Initializare controller title toolbar');

		this.control({

					'toolbarstitletoolbar menuitem[action=creazaInvestitie]' : {
						click : this.investitieNoua
					},
					'toolbarstitletoolbar menuitem[action=deschideInvestitie]' : {
						click : this.deschideInvestitie
					},
					'creazaInvestitie button[action=salveazaInvestitia]' : {
						click : this.salveazaInvestitia
					}

				});
	},

	investitieNoua : function(menuitem) {
		console.log('Creeeerreee investitie :D ');
		var view = Ext.widget('creazaInvestitie');
		view.down('form');
	},

	deschideInvestitie : function(menuitem) {
		console.log('Deschidem Investitie');
		var view = Ext.widget('deschideInvestitii');
		view.down('form');
	},

	salveazaInvestitia : function(button) {
		console.log('Salvam investitia');
		var win = button.up('window'), form = win.down('form'), record = form
				.getRecord(), values = form.getValues();

		// record.set(values);
		// console.log(values);
		var store = this.getStore('management.Investitii');
		
		store.add(values);
		win.close();
        console.log(store);
		store.sync();
	}

});
